home *** CD-ROM | disk | FTP | other *** search
-
-
-
- 5
-
-
- WHAT'S AN ASSEMBLER?
-
- What is the difference between a compiler and an assembler?
-
- A compiler is a program that takes the source code you have
- written and turns it into machine language instructions that are
- usable by the computer. A machine language instruction is a
- binary number that tells the computer to do one specific thing.
- This is something very specific like: add 1 to a specific
- variable. The compiler does this in two steps. First, the
- compiler takes each line of source code and turns the expression
- on the line into a number of simple tasks to accomplish what is
- desired, generating a number of assembler TEXT instructions and
- data definitions. When the compiler is through with the source
- code, it then takes these TEXT instructions and assembles them to
- form an object module. An object module is a file that can be
- linked with other files to form a larger program.
-
- Why two steps instead of one? There are several reasons. This
- allows a compiler writer to write a first part for any language
- like Pascal, C, BASIC, etc., and then use the same assembler
- part. This saves development time in a company that has more than
- one type of compiler. You can insert a new assembler part without
- worrying about the text generation part, or you can insert a new
- text generation part without worrying about the assembler part.
- Secondly, though an assembler is not a simple program, the
- compiler's text generator is even more complicated. Putting the
- two together is like trying to juggle eight balls instead of four
- balls.
-
- This leads to the most vital reason. Not only would a unified
- text-generator/assembler be more error prone, it would be almost
- impossible to debug. If you are getting an error due to one type
- of Pascal instruction, is this because it is being misunderstood
- by the compiler or because the compiler is giving it the wrong
- machine codes? In the two part system, the compiler writer can
- look at the intermediate text code and isolate the problem into
- one of the two halves.
-
- An assembler is a program that takes a TEXT file where each line
- corresponds to a specific machine instruction or type of data,
- calculates the address in memory where each piece of data or
- machine instruction will be, translates each instruction and
- piece of data into machine readable form, and inserts the
- addresses of data and labels into machine instructions where
- appropriate.{1}
-
-
-
- ____________________
-
- 1. A label is just a name which marks a certain spot in the
- assembler code.
-
- ______________________
-
- The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
-
-
-
-
- The PC Assembler Tutor 6
- ______________________
-
- The text name for a machine instruction is called a mnemonic.{2}
- It indicates what is being done by the instruction. Which would
- you rather use for multiplication, 'MUL' or '11110111xx100xxx'?
- These 'x's indicate a digit whose value depends on where
- something is in memory. For each mnemonic there is a single
- machine instruction which performs the operation.
-
- This means that the assembler's task is relatively simple. It
- only needs to allocate space for all the variables and
- instructions, to translate each mnemonic and data value into its
- corresponding machine code, and finally put it into a machine
- usable file.
-
- Here you need to know what different forms of file there are.
-
- 1) An executable (.EXE) file contains certain information
- for the operating system when the program is started. This
- allows the program to be as large as is wanted.
-
- 2) A .COM file contains no information for the operating
- system. When the operating system starts a .COM file it
- simply puts it in memory and starts it. Files with a .COM
- extension are limited to a length of 64k bytes.
-
- 3) Binary files are files which must be loaded into a .COM
- or .EXE program before being run. They cannot be used by
- themselves. They are archaic. They are a crutch for those
- compilers which don't support .OBJ files, and are
- disappearing.
-
- 4) An object (.OBJ) file is a section of a program. It
- contains code and variables, but also contains information
- that can be used to combine it with other object files into
- a larger program. A linker can convert one or more object
- files into an executable file.
-
-
- Things have moved along in the past few years. TurboPascal 3.0
- generated .COM files. This wasn't because .COM files were
- superior but because it was too difficult to generate the extra
- information needed to produce an .OBJ file. Interpreted BASIC
- required binary files because it did not have the ability to use
- .OBJ files. The situation now is:
-
- If you want to link with the current Turbo Pascal, you
- should use an .OBJ file. If you want to link with QuickC,
- you need an .OBJ file. If you want to combine an external
- subprogram with QuickBASIC, you need an .OBJ file. Get the
- picture?
-
- No assembler makes .EXE files. If you have a single file that you
- want made onto a stand alone .EXE file, you first make an .OBJ
- file and then use that single file with LINK.
-
- ____________________
-
- 2. You don't pronounce that first 'm'.
-
-
-
-
- Introduction 7
- ____________
-
- When making a .COM file, the normal route is to make .OBJ files,
- link them together into an EXE file, and then convert them to a
- .COM file with a program called EXE2BIN. This allows you to
- divide the problem into a number of subproblems and put them all
- together at the end.
-
- As you can see from the above, the job for the assembler is to
- take a text file and convert it into an .OBJ file. The three
- assemblers that you are most likely to have are MASM, A86, and
- TurboAssembler. They all produce object files. Since assemblers
- simply supply the machine code for each instruction, they will
- all produce the exact same code.{3}
-
- This is one of the differences between assemblers and compilers.
- The text generation phase of the compiler requires creativity. It
- is the compiler writer's idea of how to solve a certain problem
- in a specific language. This generated text is copyrighted, and
- you need a license to distribute a program that includes this
- generated text. An assembler. on the other hand, is just a
- drudge. If you had a book with the machine codes and had enough
- time, you could produce the same file byte for byte that the
- assembler would produce for a .COM file. There is no creativity
- involved in the generated code, and there is no license involved
- in its distribution.
-
- There is some difference in the speed of those three assemblers,
- but I'll have a comment about that after I give you the numbers.
- These numbers are from the time of hitting the ENTER key to the
- return of the DOS prompt ('>'). These are on a low speed machine
- so your numbers should be better, but won't be any worse.
-
- A86 TurboASM MASM
-
- one page of code 3.2 8.8 10.3
- 20 pages of code 7.3 12.7 20.4
- 60 pages of code 12.5 22.9 43.3
-
- All these numbers are in seconds. A86 is the fastest. It loads
- faster because it itself is a .COM file, and it works faster. But
- even the slowest (MASM), is fast enough. How long does it take to
- write 60 pages of code? Probably a week or two. Writing assembler
- code is normally slower than writing code for a high-level
- language. Even the slowest finishes the assembly in well under a
- minute. Think of the time it would take to compile 60 pages of
- Pascal code.
-
- In fact, the normal length of a file will be from 10 to 20 pages,
- so these are the numbers you need to think of. These will be the
- smaller .OBJ files which are linked together by the linker.
-
- If you have one of these assemblers you don't need anything
- different. If you need to get one, you can use this information
- ____________________
-
- 3. Or functionally the same code. Sometimes there are two
- different instructions that do the same thing, just as 6+1, 5+2
- and 4+3 all produce 7.
-
-
-
-
- The PC Assembler Tutor 8
- ______________________
-
- to help you in your selection. The following prices are as of
- mid-1990.
-
- A86 is available through shareware. It costs $50.00 for the
- assembler alone, $80.00 with the debugger. Add another $10.00 if
- you want a printed manual.
-
- Both MASM and Turbo Assembler come with assembler, debugger, a
- number of utility programs and several manuals. They both retail
- for $150.00, but even a quick glance at BYTE magazine will find
- you a place that is selling them for $105.00 - $110.00. They come
- bundled, so you cannot buy the assembler without the debugger
- (The Microsoft debugger is Codeview and the Borland debugger is
- Turbo Debugger).
-
- Speaking of debuggers, you may be thinking, "Well, I have DEBUG,
- so why do I want another debugger?" DEBUG has been outdated for
- several years now. It has been supplanted by symbolic debuggers
- which associate code with specific lines in the original text
- file. You give the symbolic debugger the .EXE file along with the
- text files that produced it, and it shows you your source code as
- you go along. Here's a section of code we will meet later in the
- Tutor:
-
- ; - - - - - - - - - - - - - - - - - - - -
- start: push ds ; set up for return
- sub ax,ax
- push ax
- mov ax, DATASTUFF ; load ds
- mov ds,ax
-
- outer_loop:
- lea ax, multiplicand ; load multiplicand
- call get_unsigned_8byte
- call print_unsigned_8byte
- call get_unsigned ; unsigned word to multiplier
- mov multiplier, ax
-
- lea si, multiplicand ; load pointers
- lea bx, result
- ; - - - - - - - - - - - - - - - - - - - -
-
- Don't worry about what these instructions do. You'll learn that
- later. Here is DEBUG's idea of what is going on:
-
- ******************** DEBUG SCREEN SHOT ************************
- -r
- AX=0000 BX=0000 CX=2749 DX=0000 SP=0A00 BP=0000 SI=0000 DI=0000
- DS=0D7E ES=0D7E SS=0D8E CS=0E7F NV UP DI PL NZ NA PO NC
- 0E7F:0000 1E PUSH DS
- -u0E7F:0000 2A
- 0E7F:0000 1E PUSH DS
- 0E7F:0001 2BC0 SUB AX,AX
- 0E7F:0003 50 PUSH AX
- 0E7F:0004 B82E0E MOV AX,0E2E
- 0E7F:0007 8ED8 MOV DS,AX
- 0E7F:0009 8D060800 LEA AX,[0008]
-
-
-
-
- Introduction 9
- ____________
-
- 0E7F:000D E80C14 CALL 141C
- 0E7F:0010 E84B11 CALL 115E
- 0E7F:0013 E8F505 CALL 060B
- 0E7F:0016 A31000 MOV [0010],AX
- 0E7F:0019 8D360800 LEA SI,[0008]
- 0E7F:001D 8D1E1200 LEA BX,[0012]
- ********************** END DEBUG *******************************
-
- Part of this is understandable, but a lot of it is confusing, and
- you have lost the concept of what you are trying to do. To see
- what a symbolic debugger does with the same code, here is the
- Turbo Debugger's idea of what is happening:
-
-
-
- ************************* TURBO SCREEN SHOT {4} *****************************
- File View Run Breakpoints Data Window Options READY
- .Module: debugtst File: debugtst.asm 74....................................1.
- . .
- . start: push ds ; set up for return .Registers......3. .
- . sub ax,ax . ax 5C94 .c=0. .
- . push ax . bx 0000 .z=1. .
- . . cx 0000 .s=0. .
- . mov ax, DATASTUFF ; load ds . dx 0000 .o=0. .
- . mov ds,ax . si 0000 .p=1. .
- . . di 0000 .a=0. .
- . outer_loop: . bp 0000 .i=1. .
- . lea ax, multiplicand ; load multipli. sp 09FA .d=0. .
- . call get_unsigned_8byte . ds 4AD6 . . .
- . call print_unsigned_8byte . es 4A26 . . .
- . call get_unsigned ; unsigned word. ss 4A36 . . .
- . mov multiplier, ax . cs 4B27 . . .
- . . ip 0019 . . .
- . .................. .
- . lea si, multiplicand ; load pointers .
- ..............................................................................
- .Watches....................................................................2.
- .multiplier,d 23700 .
- .multiplicand qword 00000042E843515D .
- ..............................................................................
- F1-Help F2-Bkpt F3-Close F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run
- *****************************************************************************
-
-
-
- DEBUG really doesn't meet our needs. Of course, those of you who
- still use EDLIN to write 20 page documents should feel free to
- use DEBUG.
-
- Modern language compilers have their own debuggers in their
- environments, so we only need a debugger for the assembler. Turbo
- Debugger and Code View do the job very well. D86 is better than
- DEBUG but it has some problems.
- ____________________
-
- 4. Turbo Debugger is (C) Copyright 1988-1989 Borland
- International.
-
-
-
-
- The PC Assembler Tutor 10
- ______________________
-
-
- If you actually want a debugger that will symbolically debug
- everything that supports symbolic debugging, you might want to
- take a look at the Turbo Debugger. It has more power than you are
- ever likely to need.
-
- "The Assembler Helper", the program which comes with the Tutor,
- is NOT a debugger. Debuggers are designed to show you what is
- happening with your code; the Helper is designed to show you what
- is happening with the 8086. It's a fundamental difference in
- outlook.
-
- If you want to use a debugger while you are doing this tutorial
- it is possible but the results are not guaranteed. Please see
- DEBUGGER.DOC in \COMMENTS for some information about the
- different debuggers and how to use ASMHELP with a debugger. You
- should not try to do this before you are in chapter 5 or 6.
-
- You may have noticed that CHASM, an assembler distributed through
- shareware, was not listed. There is a reason for this. It can't
- produce .OBJ files, so it cannot produce the standard files for
- use with current compilers, including QuickBASIC. CHASM is also
- unusable with this tutorial because it cannot produce files to
- link with ASMHELP.OBJ, the i/o interface program. If you are
- getting a shareware assembler, get A86. It's a quality assembler.
-
- This tutorial was originally written for those using MASM. In
- order to allow those using the Turbo Assembler and A86 to follow
- along, there is a document for each one in \COMMENTS which
- explains any differences between what is in the chapters (which
- use MASM as an example) and what the respective assemblers do.
- There aren't that many differences. The pathnames are
- \COMMENTS\TURBO.DOC and \COMMENTS\A86.DOC.
-
-
-
-
-
- 1
-
- TABLE OF CONTENTS
-
-
- Chapter 0.1 - Numbers And Arithmetic . . . . . . . . . . . i
- Base 10 Machine . . . . . . . . . . . . . . . . . . . . i
- Negative Numbers . . . . . . . . . . . . . . . . . . . ii
- 10's Complement . . . . . . . . . . . . . . . . . . . iii
- Addition . . . . . . . . . . . . . . . . . . . . . . . v
- Subtraction . . . . . . . . . . . . . . . . . . . . . . v
- Modular Math . . . . . . . . . . . . . . . . . . . . . vi
- Sign Extension . . . . . . . . . . . . . . . . . . . . ix
- Overflow . . . . . . . . . . . . . . . . . . . . . . xii
- Multiplication . . . . . . . . . . . . . . . . . . . xiii
- Division . . . . . . . . . . . . . . . . . . . . . . xiv
-
- Chapter 0.2 - Bases 2 And 16 . . . . . . . . . . . . . . . xv
- Base Conversion . . . . . . . . . . . . . . . . . . . . xv
- Binary Math . . . . . . . . . . . . . . . . . . . . . xvi
- 2's Complement . . . . . . . . . . . . . . . . . . . xvii
- Sign Extension . . . . . . . . . . . . . . . . . . xviii
-
- Chapter 0.3 - Logic . . . . . . . . . . . . . . . . . . . xxi
- AND . . . . . . . . . . . . . . . . . . . . . . . . . xxi
- OR . . . . . . . . . . . . . . . . . . . . . . . . . xxii
- XOR . . . . . . . . . . . . . . . . . . . . . . . . . xxii
- NOT . . . . . . . . . . . . . . . . . . . . . . . . xxiii
-
- Chapter 0.4 - Memory . . . . . . . . . . . . . . . . . . xxv
- Segmentation . . . . . . . . . . . . . . . . . . . . xxv
- Numbers In Memory . . . . . . . . . . . . . . . . . xxvii
-
- Chapter 0.5 - Style . . . . . . . . . . . . . . . . . . . xxix
-
-
-
- Chapter 1 - Some Simple Programs . . . . . . . . . . . . . 1
- Label . . . . . . . . . . . . . . . . . . . . . . . . . 3
- CALL . . . . . . . . . . . . . . . . . . . . . . . . . 3
- JMP . . . . . . . . . . . . . . . . . . . . . . . . . . 3
-
- Chapter 2 - Data . . . . . . . . . . . . . . . . . . . . . 11
- DB, DW, DD, DQ, DT, DF . . . . . . . . . . . . . . . . 11
- Definition of Constants . . . . . . . . . . . . . . . . 13
-
- Chapter 3 - Asmhelp . . . . . . . . . . . . . . . . . . . . 16
- Registers . . . . . . . . . . . . . . . . . . . . . . . 16
- Show_regs . . . . . . . . . . . . . . . . . . . . . . . 17
- MOV . . . . . . . . . . . . . . . . . . . . . . . . . . 19
-
- Chapter 4 - Show_regs . . . . . . . . . . . . . . . . . . . 24
- Show_reg Codes . . . . . . . . . . . . . . . . . . . . 29
-
- Chapter 5 - Addition and Subtraction . . . . . . . . . . . 31
- LOOP . . . . . . . . . . . . . . . . . . . . . . . . . 31
-
- ______________________
-
- The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
-
-
-
-
- The PC Assembler Tutor 2
- ______________________
-
- OF, ZF, SF, CF . . . . . . . . . . . . . . . . . . . . 32
- ADD . . . . . . . . . . . . . . . . . . . . . . . . . . 33
- PUSH . . . . . . . . . . . . . . . . . . . . . . . . . 33
- POP . . . . . . . . . . . . . . . . . . . . . . . . . . 34
- SUB . . . . . . . . . . . . . . . . . . . . . . . . . . 37
- JC, JNC, JO, JNO . . . . . . . . . . . . . . . . . . . 38
- INTO . . . . . . . . . . . . . . . . . . . . . . . . . 39
- INTO.COM . . . . . . . . . . . . . . . . . . . . . . . 39
-
- Chapter 6 - Multiplication and Division . . . . . . . . . . 41
- MUL . . . . . . . . . . . . . . . . . . . . . . . . . . 41
- IMUL . . . . . . . . . . . . . . . . . . . . . . . . . 41
- DIV . . . . . . . . . . . . . . . . . . . . . . . . . . 44
- IDIV . . . . . . . . . . . . . . . . . . . . . . . . . 44
-
- Chapter 7 - Logic . . . . . . . . . . . . . . . . . . . . . 47
- AND . . . . . . . . . . . . . . . . . . . . . . . . . . 47
- TEST . . . . . . . . . . . . . . . . . . . . . . . . . 49
- OR . . . . . . . . . . . . . . . . . . . . . . . . . . 50
- XOR . . . . . . . . . . . . . . . . . . . . . . . . . . 50
- NEG . . . . . . . . . . . . . . . . . . . . . . . . . . 51
- NOT . . . . . . . . . . . . . . . . . . . . . . . . . . 51
- Masks . . . . . . . . . . . . . . . . . . . . . . . . . 52
-
- Chapter 8 - Shift and Rotate . . . . . . . . . . . . . . . 56
- SAL, SHL . . . . . . . . . . . . . . . . . . . . . . . 56
- INC, DEC . . . . . . . . . . . . . . . . . . . . . . . 57
- SHR . . . . . . . . . . . . . . . . . . . . . . . . . . 58
- SAR . . . . . . . . . . . . . . . . . . . . . . . . . . 59
- ROL, ROR . . . . . . . . . . . . . . . . . . . . . . . 60
- RCL, RCR . . . . . . . . . . . . . . . . . . . . . . . 61
-
- Chapter 9 - Jumps . . . . . . . . . . . . . . . . . . . . . 68
- CMP . . . . . . . . . . . . . . . . . . . . . . . . . . 68
- Signed and Unsigned Conditional Jumps . . . . . . . . . 70
- Flag Conditional Jumps . . . . . . . . . . . . . . . . 75
- JCXZ . . . . . . . . . . . . . . . . . . . . . . . . . 75
-
- Chapter 10 - Templates . . . . . . . . . . . . . . . . . . 78
- .LST File . . . . . . . . . . . . . . . . . . . . . . . 78
- SEGMENTS . . . . . . . . . . . . . . . . . . . . . . . 84
- PUBLIC (SEGMENTS) . . . . . . . . . . . . . . . . . . . 85
- CLASS . . . . . . . . . . . . . . . . . . . . . . . . 85ff
- ENDS . . . . . . . . . . . . . . . . . . . . . . . . . 92
- ASSUME . . . . . . . . . . . . . . . . . . . . . . . . 93
- Segment Overrides . . . . . . . . . . . . . . . . . . . 93
- Subroutines . . . . . . . . . . . . . . . . . . . . . . 96
- END . . . . . . . . . . . . . . . . . . . . . . . . . . 97
- RET . . . . . . . . . . . . . . . . . . . . . . . . . . 98
- EXTRN . . . . . . . . . . . . . . . . . . . . . . . . . 99
- STACK . . . . . . . . . . . . . . . . . . . . . . . . 101
-
- Chapter 11 - Addressing Modes . . . . . . . . . . . . . . 104
- EQU . . . . . . . . . . . . . . . . . . . . . . . . . 110
- All Addressing Modes . . . . . . . . . . . . . . . . 114
- OFFSET . . . . . . . . . . . . . . . . . . . . . . . 118
- SEG . . . . . . . . . . . . . . . . . . . . . . . . . 118
-
-
-
-
- Table Of Contents 3
- _________________
-
- LEA . . . . . . . . . . . . . . . . . . . . . . . . . 118
-
- Chapter 12 - Multiple Word Arithmetic I . . . . . . . . . 122
- ADC . . . . . . . . . . . . . . . . . . . . . . . . . 123
- CLC . . . . . . . . . . . . . . . . . . . . . . . . . 124
- SBB . . . . . . . . . . . . . . . . . . . . . . . . . 126
-
- Chapter 13 - Multiple Word Arithmetic II . . . . . . . . 129
- Unsigned Multiplication . . . . . . . . . . . . . . . 129
- Unsigned Division . . . . . . . . . . . . . . . . . . 130
-
- Chapter 14 - Zoom . . . . . . . . . . . . . . . . . . . . 134
-
- Chapter 15 - Subroutines . . . . . . . . . . . . . . . . 137
- PUSHREGS.MAC . . . . . . . . . . . . . . . . . . . . 137
- EXTRN in Subroutines . . . . . . . . . . . . . . . . 142
- Passing Data . . . . . . . . . . . . . . . . . . . . 144
- Near and Far Procedures . . . . . . . . . . . . . . . 145
- The Stack . . . . . . . . . . . . . . . . . . . . . . 148
- Types of Returns . . . . . . . . . . . . . . . . . . 153
- PUSHREGS . . . . . . . . . . . . . . . . . . . . . . 154
- POPREGS . . . . . . . . . . . . . . . . . . . . . . . 154
- LDS . . . . . . . . . . . . . . . . . . . . . . . . . 157
- LES . . . . . . . . . . . . . . . . . . . . . . . . . 157
- Towers of Hanoi . . . . . . . . . . . . . . . . . . . 162
- Summary . . . . . . . . . . . . . . . . . . . . . . . 166
-
- Chapter 16 - Long Signed Multiplication And Division . . 170
- Long Negation . . . . . . . . . . . . . . . . . . . . 170
-
- Chapter 17 - Interrupts . . . . . . . . . . . . . . . . . 177
- INT . . . . . . . . . . . . . . . . . . . . . . . . . 177
- NMI . . . . . . . . . . . . . . . . . . . . . . . . . 181
- IEF . . . . . . . . . . . . . . . . . . . . . . . . . 181
- STI . . . . . . . . . . . . . . . . . . . . . . . . . 181
- CLI . . . . . . . . . . . . . . . . . . . . . . . . . 181
- INT 3 . . . . . . . . . . . . . . . . . . . . . . . . 182
-
- Chapter 18 - Ports . . . . . . . . . . . . . . . . . . . 185
- IN . . . . . . . . . . . . . . . . . . . . . . . . . 185
- OUT . . . . . . . . . . . . . . . . . . . . . . . . . 186
- Parity . . . . . . . . . . . . . . . . . . . . . . . 186
-
- Chapter 19 - Strings . . . . . . . . . . . . . . . . . . 191
- SCAS . . . . . . . . . . . . . . . . . . . . . . . . 191
- DF . . . . . . . . . . . . . . . . . . . . . . . . . 191
- REP/REPE/REPNE . . . . . . . . . . . . . . . . . . . 195
- STOS . . . . . . . . . . . . . . . . . . . . . . . . 196
- LODS . . . . . . . . . . . . . . . . . . . . . . . . 198
- MOVS . . . . . . . . . . . . . . . . . . . . . . . . 199
- CMPS . . . . . . . . . . . . . . . . . . . . . . . . 204
- Segment Overrides . . . . . . . . . . . . . . . . . . 207
- REP and Overrides . . . . . . . . . . . . . . . . . . 209
-
- Chapter 20 - Control Structures . . . . . . . . . . . . . 212
- IF . . . . . . . . . . . . . . . . . . . . . . . . . 212
- WHILE . . . . . . . . . . . . . . . . . . . . . . . . 214
-
-
-
-
- The PC Assembler Tutor 4
- ______________________
-
- DO-WHILE . . . . . . . . . . . . . . . . . . . . . . 215
- BREAK . . . . . . . . . . . . . . . . . . . . . . . . 215
- CONTINUE . . . . . . . . . . . . . . . . . . . . . . 215
- FOR . . . . . . . . . . . . . . . . . . . . . . . . . 216
- SWITCH . . . . . . . . . . . . . . . . . . . . . . . 217
-
- Chapter 21 - .COM Files . . . . . . . . . . . . . . . . . 219
- .COM Template . . . . . . . . . . . . . . . . . . . . 219
- PSP . . . . . . . . . . . . . . . . . . . . . . . . . 220
- ASSUME . . . . . . . . . . . . . . . . . . . . . . . 221
- Phase Errors . . . . . . . . . . . . . . . . . . . . 221
-
- Chapter 22 - BCD Numbers . . . . . . . . . . . . . . . . 229
- Unpacked BCD . . . . . . . . . . . . . . . . . . . . 229
- Packed BCD . . . . . . . . . . . . . . . . . . . . . 230
- DAA . . . . . . . . . . . . . . . . . . . . . . . . . 232
- DAS . . . . . . . . . . . . . . . . . . . . . . . . . 233
- AAA . . . . . . . . . . . . . . . . . . . . . . . . . 240
- AAS . . . . . . . . . . . . . . . . . . . . . . . . . 242
- AAM . . . . . . . . . . . . . . . . . . . . . . . . . 242
- AAD . . . . . . . . . . . . . . . . . . . . . . . . . 243
- Unpacking . . . . . . . . . . . . . . . . . . . . . . 245
- Packing . . . . . . . . . . . . . . . . . . . . . . . 246
-
- Chapter 23 - XLAT . . . . . . . . . . . . . . . . . . . . 253
- EBCDIC Numbers . . . . . . . . . . . . . . . . . . . 253
- XLAT . . . . . . . . . . . . . . . . . . . . . . . . 253
- Translation Table . . . . . . . . . . . . . . . . . . 253
-
- Chapter 24 - Miscellaneous Instructions . . . . . . . . . 264
- XCHG . . . . . . . . . . . . . . . . . . . . . . . . 264
- ESC . . . . . . . . . . . . . . . . . . . . . . . . . 264
- WAIT . . . . . . . . . . . . . . . . . . . . . . . . 264
- FWAIT . . . . . . . . . . . . . . . . . . . . . . . . 264
- LOCK . . . . . . . . . . . . . . . . . . . . . . . . 265
- LOOPE/LOOPNE . . . . . . . . . . . . . . . . . . . . 265
- HALT . . . . . . . . . . . . . . . . . . . . . . . . 266
- CMC . . . . . . . . . . . . . . . . . . . . . . . . . 266
- LAHF . . . . . . . . . . . . . . . . . . . . . . . . 266
- SAHF . . . . . . . . . . . . . . . . . . . . . . . . 267
- NOP . . . . . . . . . . . . . . . . . . . . . . . . . 267
-
- Chapter 25 - What Does It All Mean? . . . . . . . . . . . 268
- Interrupts . . . . . . . . . . . . . . . . . . . . . 269
- Data Bus . . . . . . . . . . . . . . . . . . . . . . 273
- Alignment Type . . . . . . . . . . . . . . . . . . . 274
-
- Chapter 26 - Simplifying The Template . . . . . . . . . . 276
- INT 21h Function 4Ch . . . . . . . . . . . . . . . . 276
- Exit Code . . . . . . . . . . . . . . . . . . . . . . 276
- Standardized Segments . . . . . . . . . . . . . . . . 277
- _DATA . . . . . . . . . . . . . . . . . . . . . . . . 279
- _BSS . . . . . . . . . . . . . . . . . . . . . . . . 279
- CONST . . . . . . . . . . . . . . . . . . . . . . . . 280
- Literals . . . . . . . . . . . . . . . . . . . . . . 280
- STACK . . . . . . . . . . . . . . . . . . . . . . . . 280
- Groups . . . . . . . . . . . . . . . . . . . . . . . 280
-
-
-
-
- Table Of Contents 5
- _________________
-
- DGROUP . . . . . . . . . . . . . . . . . . . . . . . 281
- Groups and OFFSET . . . . . . . . . . . . . . . . . . 284
- Standardized Segment Names . . . . . . . . . . . . . 287
- Standardized Segment Directives . . . . . . . . . . . 288
- .MODEL Names . . . . . . . . . . . . . . . . . . . . 291
- Summary . . . . . . . . . . . . . . . . . . . . . . . 293
-
- APPENDIX
-
- Appendix I - The PC Assembler Helper . . . . . . . . . . . i
- Appendix II - The 8086 Instruction Set . . . . . . . . . xiii
- Appendix III - Instruction Speed And Flags . . . . . . xxvii
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- ANCILLARY MATERIAL
-
-
- DEBUGGERS (DEBUGGER.DOC)
- TASM (TASM.DOC)
- A86 (A86.DOC)
-
-
-
- BASIC (BASIC1.DOC, BASIC2-1.DOC, BASIC2-2.DOC)
- Using Basic . . . . . . . . . . . . . . . . . . . . . . . mmi
- Variable Typing . . . . . . . . . . . . . . . . . . . mmi
- Default Type . . . . . . . . . . . . . . . . . . . . mmii
-
- Interfacing Basic With Assembler . . . . . . . . . . . mmvii
- Memory Allocation . . . . . . . . . . . . . . . . . mmvii
- String Allocation . . . . . . . . . . . . . . . . . mmviii
- Data Output . . . . . . . . . . . . . . . . . . . . . mmx
- FIELD . . . . . . . . . . . . . . . . . . . . . . . mmxii
- LSET/MID$/RSET . . . . . . . . . . . . . . . . . . mmxiii
- MKI$, MKL$, MKS$, MKD$ . . . . . . . . . . . . . . mmxiii
- CVI, CVL, CVS, CVD . . . . . . . . . . . . . . . . mmxiii
- STR$, VAL . . . . . . . . . . . . . . . . . . . . . mmxiv
- VARPTR . . . . . . . . . . . . . . . . . . . . . . mmxvi
- PTR86 (Basic 3.0) . . . . . . . . . . . . . . . . . mmxvii
- BUILDLIB.EXE . . . . . . . . . . . . . . . . . . . mmxvii
- VARSEG (Basic 4.0) . . . . . . . . . . . . . . . mmxviii
- Basic Calling Conventions . . . . . . . . . . . . . mmxix
- INT86 . . . . . . . . . . . . . . . . . . . . . . mxxviii
- SADD . . . . . . . . . . . . . . . . . . . . . . . mmxxix
- BLOAD . . . . . . . . . . . . . . . . . . . . . . . mmxxx
- Summary . . . . . . . . . . . . . . . . . . . . . . mmxxxi
- Interfacing Basic With Assembler . . . . . . . . . mmvii
-
-
- Ancillary Programs (MISHMASH.DOC)
- General Block Move . . . . . . . . . . . . . . . . . . 1
- Block Multiplication . . . . . . . . . . . . . . . . . 3
- Binary Multiplication . . . . . . . . . . . . . . . . . 6
- Binary Division . . . . . . . . . . . . . . . . . . . . 9
-
-
-
-
-
- 294
-
- INDEX
-
-
- AAA . . . . . . . . . . . .240 Far Procedures. . . . . . .145
- AAD . . . . . . . . . . . .243 Flag Conditional Jumps. . . 75
- AAM . . . . . . . . . . . .242 FOR . . . . . . . . . . . .216
- AAS . . . . . . . . . . . .242 FWAIT . . . . . . . . . . .264
- ADC . . . . . . . . . . . .123
- ADD . . . . . . . . . . . . 33 Groups. . . . . . . . . . .280
- Addition. . . . . . . . . . .v Groups and OFFSET . . . . .284
- Addressing Modes. . . . . .114
- Alignment Type. . . . . . .274 HALT. . . . . . . . . . . .266
- AND . . . . . . . . . .xxi, 47
- ASSUME. . . . . . . . .93, 221 IDIV. . . . . . . . . . . . 44
- IEF . . . . . . . . . . . .181
- Base 10 Machine . . . . . . .i IF. . . . . . . . . . . . .212
- Base Conversion . . . . . . xv IMUL. . . . . . . . . . . . 41
- Binary Math . . . . . . . .xvi IN. . . . . . . . . . . . .185
- BREAK . . . . . . . . . . .215 INC . . . . . . . . . . . . 57
- _BSS. . . . . . . . . . . .279 INT . . . . . . . . . . . .177
- INT 21h Function 4h . . . .276
- CALL. . . . . . . . . . . . .3 INT 3 . . . . . . . . . . .182
- CF. . . . . . . . . . . . . 32 Interrupts. . . . . . . . .269
- CLASS . . . . . . . . . . 85ff INTO. . . . . . . . . . . . 39
- CLC . . . . . . . . . . . .124 INTO.COM. . . . . . . . . . 39
- CLI . . . . . . . . . . . .181
- CMC . . . . . . . . . . . .266 JUMPS . . . . . . . . . . . 70
- CMP . . . . . . . . . . . . 68 JC, JNC . . . . . . . . . . 38
- CMPS. . . . . . . . . . . .204 JCXZ. . . . . . . . . . . . 75
- .COM Template . . . . . . .219 JMP . . . . . . . . . . . . .3
- CONST . . . . . . . . . . .280 JO, JNO . . . . . . . . . . 38
- CONTINUE. . . . . . . . . .215
- Label . . . . . . . . . . . .3
- DAA . . . . . . . . . . . .232 LAHF. . . . . . . . . . . .266
- DAS . . . . . . . . . . . .233 LDS . . . . . . . . . . . .157
- _DATA . . . . . . . . . . .279 LEA . . . . . . . . . . . .118
- Data Bus. . . . . . . . . .273 LES . . . . . . . . . . . .157
- DB, DW, DD, DQ, DT, DF. . . 11 Literals. . . . . . . . . .280
- DEC . . . . . . . . . . . . 57 LOCK. . . . . . . . . . . .265
- Definition of Constants . . 13 LODS. . . . . . . . . . . .198
- DF. . . . . . . . . . . . .191 Long Negation . . . . . . .170
- DGROUP. . . . . . . . . . .281 LOOP. . . . . . . . . . . . 31
- DIV . . . . . . . . . . . . 44 LOOPE/LOOPZ . . . . . . . .265
- Division. . . . . . . . . .xiv LOOPNE/LOOPNZ . . . . . . .265
- DO-WHILE. . . . . . . . . .215 .LST File . . . . . . . . . 78
-
- EBCDIC Numbers. . . . . . .253 Masks . . . . . . . . . . . 52
- END . . . . . . . . . . . . 97 .MODEL Names. . . . . . . .291
- ENDS. . . . . . . . . . . . 92 Modular Math. . . . . . . . vi
- EQU . . . . . . . . . . . .110 MOV . . . . . . . . . . . . 19
- ESC . . . . . . . . . . . .264 MOVS. . . . . . . . . . . .199
- Exit Code . . . . . . . . .276 MUL . . . . . . . . . . . . 41
- EXTRN . . . . . . . . . . . 99 Multiplication. . . . . . xiii
- EXTRN in Subroutines. . . .142
-
- ______________________
-
- The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
-
-
-
-
- 295
-
- Near Procedures . . . . . .145 Sign Extension. . . . . . . ix
- NEG . . . . . . . . . . . . 51 Sign Extension. . . . . .xviii
- Negative Numbers. . . . . . ii Signed Jumps. . . . . . . . 70
- NMI . . . . . . . . . . . .181 STACK . . . . . . . . . . .101
- NOP . . . . . . . . . . . .267 STACK . . . . . . . . . . .280
- NOT . . . . . . . . . . . . 51 Standardized
- NOT . . . . . . . . . . .xxiii Segment Directives . . .288
- Numbers In Memory . . . .xxvii Segment Names. . . . . .287
- Segments . . . . . . . .277
- OF. . . . . . . . . . . . . 32 STI . . . . . . . . . . . .181
- OFFSET. . . . . . . . . . .118 STOS. . . . . . . . . . . .196
- OR. . . . . . . . . . . . . 50 SUB . . . . . . . . . . . . 37
- OR. . . . . . . . . . . . xxii Subroutines . . . . . . . . 96
- OUT . . . . . . . . . . . .186 Subtraction . . . . . . . . .v
- Overflow. . . . . . . . . .xii SWITCH. . . . . . . . . . .217
-
- Packed BCD. . . . . . . . .230 Ten's Complement. . . . . .iii
- Packing BCDs. . . . . . . .246 TEST. . . . . . . . . . . . 49
- Parity. . . . . . . . . . .186 The Stack . . . . . . . . .148
- Passing Data. . . . . . . .144 Towers of Hanoi . . . . . .162
- Phase Errors. . . . . . . .221 Translation Table . . . . .253
- POP . . . . . . . . . . . . 34 Two's Complement. . . . . xvii
- POPREGS . . . . . . . . . .154 Types of Returns. . . . . .153
- PSP . . . . . . . . . . . .220
- PUBLIC (Data) . . . . . . .142 Unpacked BCD. . . . . . . .229
- PUBLIC (SEGMENTS) . . . . . 85 Unpacking BCDs. . . . . . .245
- PUSH. . . . . . . . . . . . 33 Unsigned Division . . . . .130
- PUSHREGS. . . . . . . . . .154 Unsigned Jumps. . . . . . . 70
- PUSHREGS.MAC. . . . . . . .137 Unsigned Multiplication . .129
-
- RCL, RCR. . . . . . . . . . 61 WAIT. . . . . . . . . . . .264
- Registers . . . . . . . . . 16 WHILE . . . . . . . . . . .214
- REP . . . . . . . . . . . .195
- REP and Overrides . . . . .209 XCHG. . . . . . . . . . . .264
- REPE/REPZ . . . . . . . . .195 XLAT. . . . . . . . . . . .253
- REPNE/REPNZ . . . . . . . .195 XOR . . . . . . . . . . . . 50
- RET . . . . . . . . . . . . 98 XOR . . . . . . . . . . . xxii
- ROL, ROR. . . . . . . . . . 60
- ZF. . . . . . . . . . . . . 32
- SAHF. . . . . . . . . . . .267
- SAL . . . . . . . . . . . . 56
- SAR . . . . . . . . . . . . 59
- SBB . . . . . . . . . . . .126
- SCAS. . . . . . . . . . . .191
- SEG (operator). . . . . . .118
- SEGMENT . . . . . . . . . . 84
- Segment Overrides . . . . . 93
- Segment Overrides . . . . .207
- Segmentation. . . . . . . .xxv
- SF. . . . . . . . . . . . . 32
- SHL . . . . . . . . . . . . 56
- Show_reg Codes. . . . . . . 29
- Show_regs . . . . . . . . . 17
- SHR . . . . . . . . . . . . 58
-
-